package com.base.app_core.model.dto;

import android.os.Parcel;
import android.os.Parcelable;

import com.blankj.utilcode.util.StringUtils;
import com.tencent.map.geolocation.TencentLocation;


/**
 * Created by Administrator on 22/03/2018.
 */

public class PacketDto implements Parcelable {

    private double latitude;
    private double longitude;
    private String city;
    private String province;
    private String address;
    private String district;
    private String village;
    private int range = 1000;
    private String name;
    private String provinceCode;
    private String cityCode;
    private String areaCode;

    public String getProvinceCode() {
        return provinceCode;
    }

    public void setProvinceCode(String provinceCode) {
        this.provinceCode = provinceCode;
    }

    public String getCityCode() {
        return cityCode;
    }

    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getRange() {
        return range;
    }

    public void setRange(int range) {
        this.range = range;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCity() {
        return city;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getProvince() {
        return province;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAddress() {
        return address;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getDistrict() {
        return district;
    }

    public void setVillage(String village) {
        this.village = village;
    }

    public String getVillage() {
        return village;
    }

    public void fillData(TencentLocation location) {
        System.out.println(location.toString());
        setLatitude(location.getLatitude());
        setLongitude(location.getLongitude());
        setCity(location.getCity());
        setProvince(location.getProvince());
        setAddress(location.getAddress());
        setDistrict(location.getDistrict());
        setVillage(location.getVillage());
        setName(location.getName());
    }

    public PacketDto() {
    }

    /**
     * -3 全国 -2 全省 -1 全市 0 区/县 1 1km , 3 3km, 5 5km, 10 10km
     *
     * @param item
     */
    public void setRangeAction(SelectDisRangeDto item) {
        if (item == null || StringUtils.isEmpty(item.getRangeStr())) {
            return;
        }
        String rangeStr = item.getRangeStr();
        if (rangeStr.equals("1km")) {
            setRange(1000);
        } else if (rangeStr.equals("3km")) {
            setRange(3000);
        } else if (rangeStr.equals("5km")) {
            setRange(5000);
        } else if (rangeStr.equals("10km")) {
            setRange(10 * 1000);
        } else if (rangeStr.equals("区/县")) {
            setRange(0);
        } else if (rangeStr.equals("全市")) {
            setRange(-1);
        } else if (rangeStr.equals("全省")) {
            setRange(-2);
        } else if (rangeStr.equals("全国")) {
            setRange(-3);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeDouble(this.latitude);
        dest.writeDouble(this.longitude);
        dest.writeString(this.city);
        dest.writeString(this.province);
        dest.writeString(this.address);
        dest.writeString(this.district);
        dest.writeString(this.village);
        dest.writeInt(this.range);
        dest.writeString(this.name);
        dest.writeString(this.provinceCode);
        dest.writeString(this.cityCode);
        dest.writeString(this.areaCode);
    }

    protected PacketDto(Parcel in) {
        this.latitude = in.readDouble();
        this.longitude = in.readDouble();
        this.city = in.readString();
        this.province = in.readString();
        this.address = in.readString();
        this.district = in.readString();
        this.village = in.readString();
        this.range = in.readInt();
        this.name = in.readString();
        this.provinceCode = in.readString();
        this.cityCode = in.readString();
        this.areaCode = in.readString();
    }

    public static final Creator<PacketDto> CREATOR = new Creator<PacketDto>() {
        @Override
        public PacketDto createFromParcel(Parcel source) {
            return new PacketDto(source);
        }

        @Override
        public PacketDto[] newArray(int size) {
            return new PacketDto[size];
        }
    };
}
